package com.sendables;

import java.awt.Color;
import java.awt.Graphics;

import com.exception.IllegalPackageException;

public class Line extends Paintable {
	private DoodlePoint	to;

	public Line(int ownerId, Color c, DoodlePoint start, DoodlePoint to, byte temporary)
	{
		super(ownerId, c, start);
		this.to = to;
	}

	public Line()
	{
		super();
	}

	public void paint(Graphics g)
	{
		g.setColor(c);
		g.drawLine(start.getX(), start.getY(), to.getX(), to.getY());
		g.drawLine(start.getX(), start.getY() - 1, to.getX(), to.getY() - 1);
	}

	@Override
	public void writeByteRepresentation(byte[] b, int[] offset)
	{
		b[offset[0]++] = Sendable.LINE;
		super.writeByteRepresentation(b, offset);
		to.writeByteRepresentation(b, offset);
	}

	public String toString()
	{
		return getClass().getCanonicalName() + super.toString() + " To: " + to;
	}

	public Sendable parse(byte[] b, int[] offset) throws IllegalPackageException
	{
		if (b[offset[0]++] != Sendable.LINE)
			throw new IllegalPackageException("Trying to parse something that isnt a line in class: Line");
		parseSuper(b, offset);
		to = DoodlePoint.parse(b, offset);
		return this;
	}

	@Override
	public int getAlloc()
	{
		return to.getAlloc() + super.getAlloc();
	}

}
